package Game;

import Java01.Poker;
import Java01.PokerManager;

import java.util.Objects;
import java.util.Scanner;

public class Game implements gameEnvironment {
    private int packPot;
    Scanner sc = new Scanner(System.in);
    public void begin(PersonPlayer player){
        player.initID();
        player.initMoney();
        player.initName();
        player.pokerPrint();
    }

    @Override
    public int bet(PersonPlayer player) {
        System.out.print("轮到您下注，请输入下注金额：" + " ");
        int money = sc.nextInt();
        player.setMoney(player.getMoney() - money);
        System.out.println("您当前余额为: " + (player.getMoney()));
        packPot += money;
        return money;
    }

    @Override
    public int withBet(PersonPlayer player, int money) {
        System.out.println("是否跟注？(y/n)");
        String input = sc.next();
        if (Objects.equals(input, "y")){
            System.out.println("请输入下注金额");
            int withBetMoney = sc.nextInt();
            while (money > withBetMoney) {
                System.out.print("你下注金额至少为: " + money + "\n" + "请重新输入");
                withBetMoney = sc.nextInt();
            }
            player.setMoney(player.getMoney() - money);
            packPot += withBetMoney;
        }
        return packPot;
    }

    @Override
    public void disCard(PersonPlayer player,int flag) {
        System.out.println("是否弃牌？(y/n)");
        String input = sc.next();
        int balance = player.getMoney();
        if (Objects.equals(input, "y")){
            System.out.println("您已弃牌，剩余金额为 " + balance);
        }else {
            System.out.println("您选择了继续,剩余金额为" + balance);
        }

    }

    @Override
    public int allIn(PersonPlayer player,int flag) {
        System.out.println("是否梭哈？(y/n)");
        String input = sc.next();
        if (Objects.equals(input, "y")){
            packPot = player.getMoney();
            player.setMoney(0);
            System.out.println("您的余额为：" + player.getMoney());
            return 1;
        }else return 0;

    }

    @Override
    public boolean CompareCard(PersonPlayer player,PersonPlayer anotherPlayer,PokerManager pokerManager) {
        return true;
    }


}
